|
RAIS
3.2
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Text; 00004 using NUnit.Framework; 00005 using RAIS.Common.UserManagement; 00006 using RAIS.DataAccessLayer; 00007 00008 namespace RAIS.DataAccessLayerTest.CommonClasses 00009 { 00010 [TestFixture] 00011 public class DataRoleTest 00012 { 00013 private int expectedID = 1; 00014 private string expectedName = "Test Data Role"; 00015 private string expectedRegionName = "Test Region"; 00016 private string expectedDistrictName = "Test District"; 00017 private string expectedFacilityName = "Test Facility"; 00018 private DataRoleAttribute expectedDataRoleAttribute = new DataRoleAttribute(); 00019 00020 private DataRole dataRole; 00021 00022 [SetUp] 00023 public void Init() 00024 { 00025 this.expectedDataRoleAttribute.Region = new Region(); 00026 this.expectedDataRoleAttribute.Region.Name = this.expectedRegionName; 00027 this.expectedDataRoleAttribute.District = new District(); 00028 this.expectedDataRoleAttribute.District.Name = this.expectedDistrictName; 00029 this.expectedDataRoleAttribute.Facility = new Facility(); 00030 this.expectedDataRoleAttribute.Facility.Name = this.expectedFacilityName; 00031 00032 dataRole = new DataRole(); 00033 dataRole.ID = this.expectedID; 00034 dataRole.Name = this.expectedName; 00035 dataRole.Attributes.Add(this.expectedDataRoleAttribute.ToString(), this.expectedDataRoleAttribute); 00036 } 00037 [Test] 00038 public void GetID() 00039 { 00040 // Test 00041 Assert.AreEqual(this.expectedID, this.dataRole.ID); 00042 } 00043 [Test] 00044 public void GetName() 00045 { 00046 // Test 00047 Assert.AreEqual(this.expectedName, this.dataRole.Name); 00048 } 00049 [Test] 00050 public void GetAttributes() 00051 { 00052 // Test 00053 Assert.AreEqual(this.expectedDataRoleAttribute 00054 , this.dataRole.Attributes[this.expectedDataRoleAttribute.ToString()]); 00055 } 00056 [Test] 00057 public void SetName() 00058 { 00059 // Preparation 00060 string expectedNewName = "New Test DataRole"; 00061 00062 // Test 00063 this.dataRole.Name = expectedNewName; 00064 00065 // Check 00066 Assert.AreEqual(expectedNewName, this.dataRole.Name); 00067 } 00068 [Test] 00069 public void ValidateNewAttribute_AttributeExists() 00070 { 00071 bool returnStatus; 00072 string errorMessage = ""; 00073 00074 // Test 00075 returnStatus = dataRole.ValidateNewAttribute(this.expectedDataRoleAttribute, ref errorMessage); 00076 00077 // Check 00078 Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:"); 00079 Assert.AreEqual(RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_EXISTS, errorMessage); 00080 } 00081 [Test] 00082 public void ValidateNewAttribute_RegionRestriction() 00083 { 00084 bool returnStatus; 00085 string errorMessage = ""; 00086 DataRoleAttribute newDataRoleAttribute = new DataRoleAttribute(); 00087 newDataRoleAttribute.Region = new Region(); 00088 newDataRoleAttribute.Region.Name = RAIS.Common.Constants.ALL_REGIONS; 00089 newDataRoleAttribute.District = new District(); 00090 newDataRoleAttribute.District.Name = this.expectedDistrictName; 00091 newDataRoleAttribute.Facility = new Facility(); 00092 newDataRoleAttribute.Facility.Name = this.expectedFacilityName; 00093 00094 // Test 00095 returnStatus = dataRole.ValidateNewAttribute(newDataRoleAttribute, ref errorMessage); 00096 00097 // Check 00098 Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:"); 00099 Assert.AreEqual(RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_CONFLICT, errorMessage); 00100 } 00101 [Test] 00102 public void ValidateNewAttribute_DistrictRestriction() 00103 { 00104 bool returnStatus; 00105 string errorMessage = ""; 00106 DataRoleAttribute newDataRoleAttribute = new DataRoleAttribute(); 00107 newDataRoleAttribute.Region = new Region(); 00108 newDataRoleAttribute.Region.Name = this.expectedRegionName; 00109 newDataRoleAttribute.District = new District(); 00110 newDataRoleAttribute.District.Name = RAIS.Common.Constants.ALL_DISTRICTS; 00111 newDataRoleAttribute.Facility = new Facility(); 00112 newDataRoleAttribute.Facility.Name = this.expectedFacilityName; 00113 00114 // Test 00115 returnStatus = dataRole.ValidateNewAttribute(newDataRoleAttribute, ref errorMessage); 00116 00117 // Check 00118 Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:"); 00119 Assert.AreEqual(RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_CONFLICT, errorMessage); 00120 } 00121 [Test] 00122 public void ValidateNewAttribute_FacilityRestriction() 00123 { 00124 bool returnStatus; 00125 string errorMessage = ""; 00126 DataRoleAttribute newDataRoleAttribute = new DataRoleAttribute(); 00127 newDataRoleAttribute.Region = new Region(); 00128 newDataRoleAttribute.Region.Name = this.expectedRegionName; 00129 newDataRoleAttribute.District = new District(); 00130 newDataRoleAttribute.District.Name = this.expectedDistrictName; 00131 newDataRoleAttribute.Facility = new Facility(); 00132 newDataRoleAttribute.Facility.Name = RAIS.Common.Constants.ALL_FACILITIES; 00133 00134 // Test 00135 returnStatus = dataRole.ValidateNewAttribute(newDataRoleAttribute, ref errorMessage); 00136 00137 // Check 00138 Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:"); 00139 Assert.AreEqual(RAIS.Common.Messages.DATA_ROLE_ATTRIBUTE_CONFLICT, errorMessage); 00140 } 00141 [Test] 00142 public void ContainsRegionRestriction() 00143 { 00144 bool returnStatus; 00145 00146 // Test 00147 returnStatus = dataRole.ContainsRegionRestriction(expectedRegionName); 00148 00149 // Check 00150 Assert.IsTrue(returnStatus, "ContainsRegionRestriction return status error:"); 00151 } 00152 } 00153 }